# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import shutil

class Recipe(recipe.Recipe):
    name = 'gettext-m4'
    version = '0.20.1'
    stype = SourceType.TARBALL
    url = 'gnu://gettext/gettext-%(version)s.tar.xz'
    tarball_dirname = 'gettext-%(version)s'
    tarball_checksum = '53f02fbbec9e798b0faaf7c73272f83608e835c6288dd58be6c9bb54624a3800'
    # only libraries are LGPLv2+, tools are GPLv3+ and defined below
    licenses = [License.LGPLv2Plus]
    autoreconf = True
    btype = BuildType.CUSTOM

    files_devel = [
            'share/aclocal/codeset.m4',
            'share/aclocal/fcntl-o.m4',
            'share/aclocal/gettext.m4',
            'share/aclocal/glibc2.m4',
            'share/aclocal/glibc21.m4',
            'share/aclocal/iconv.m4',
            'share/aclocal/intdiv0.m4',
            'share/aclocal/intl.m4',
            'share/aclocal/intldir.m4',
            'share/aclocal/intlmacosx.m4',
            'share/aclocal/intmax.m4',
            'share/aclocal/inttypes-pri.m4',
            'share/aclocal/inttypes_h.m4',
            'share/aclocal/lcmessage.m4',
            'share/aclocal/lib-ld.m4',
            'share/aclocal/lib-link.m4',
            'share/aclocal/lib-prefix.m4',
            'share/aclocal/lock.m4',
            'share/aclocal/longlong.m4',
            'share/aclocal/nls.m4',
            'share/aclocal/po.m4',
            'share/aclocal/printf-posix.m4',
            'share/aclocal/progtest.m4',
            'share/aclocal/size_max.m4',
            'share/aclocal/stdint_h.m4',
            'share/aclocal/threadlib.m4',
            'share/aclocal/uintmax_t.m4',
            'share/aclocal/visibility.m4',
            'share/aclocal/wchar_t.m4',
            'share/aclocal/wint_t.m4',
            'share/aclocal/xsize.m4',
            ]

    def post_install(self):
        m4dir = os.path.join(self.build_dir, 'gettext-runtime', 'm4')
        for f in [x for x in os.listdir(m4dir) if x.endswith('.m4')]:
            shutil.copy(os.path.join(m4dir, f),
                    os.path.join(self.config.prefix, 'share', 'aclocal'))
        m4dir = os.path.join(self.build_dir, 'gettext-runtime', 'gnulib-m4')
        for f in ['lib-ld.m4', 'lib-prefix.m4', 'lib-link.m4']:
            shutil.copy(os.path.join(m4dir, f),
                    os.path.join(self.config.prefix, 'share', 'aclocal'))
        super().post_install()
